<?php

class Category_model extends MY_Model {

	public $primary_table = 'flat_php_categories';
	public $fields = array('id','name');

	function count_books($options = array())
	{
		$this->db->select('c.*, COUNT(b.id) AS qty_books', TRUE);
		$this->db->join('flat_php_books b', 'c.id = b.categories_id', 'left');
		$this->db->group_by('c.id');
		$q = $this->db->get($this->primary_table . ' c');

		return $q->result_array();
	}
}
